#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>

typedef struct list
{
    int num;
    list* next;
}list;

int main()
{
    //(list*)malloc(sizeof(list)' } ' != c
    int count = 0;
    int k = 0;
    char c = 0;
    int i = 0;
    list* l = new list;
    list* p = l;
    while('}'!=c)
    {
        p->next = new list;
        p = p->next;
        scanf("%d", &p->num);
        c = getchar();
        count++;
    }
    p->next = NULL;
    scanf("%d", &k);

    putchar('{');
    if (k < count)
    {
        list* temp = l;
        p = l;
        for (i = 0; i < k; i++)
        {
            p = p->next;
        }
        while (p)
        {
            p = p->next;
            temp = temp->next;
        }
        while (1)
        {
            printf("%d", temp->num);
            temp = temp->next;
            if (!temp)
            {
                break;
            }
            putchar(',');
        }
    }
    putchar('}');

    return 0;
}